<template>
  <div id="shopclassifylist"> 

          <el-table :data="datalist" style="width: 100%" :height="dtheight" :header-cell-style="{background:'#4F81BC',color:'white'}"
           :row-class-name="tableRowClassName"  :border="true">
                
                <el-table-column label="排序"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.rank }}</span>
                    </template>
                </el-table-column>

                <el-table-column label="名称"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.cname }}</span>
                    </template>
                </el-table-column>  
                <el-table-column label="颜色"  align='center' >                   
                    <template slot-scope="scope">                   
                        <span >{{ scope.row.color }}</span>
                    </template>
                </el-table-column> 

                <el-table-column label="图片"  align='center' >                   
                    <template slot-scope="scope">                   
                         <img  style="width: 30px; height: 30px" :src="urlimg + scope.row.icon" /> 
                    </template>
                </el-table-column> 
  
               
                 <el-table-column label="操作" align='center' width="300px">
                    <template slot-scope="scope"> 
                        <el-button size="mini"  type="primary"  class="button_class1"   plain @click="xg_but(scope.row)">修改</el-button> 
                        <el-button size="mini"  type="primary" class="button_class2"  plain @click="delect_but(scope.row)">删除</el-button>
                        <el-button size="mini"  type="primary" class="button_class1"  plain @click="mtk1_but(scope.row)">排序</el-button>
                    </template>
                </el-table-column>        

  
            </el-table>  


               <!-- 修改分类 -->
    <el-dialog title="修改分类" :visible.sync="xg_mtk"  width="500px" :close-on-click-modal="false">
        <div style="width:100%;"> 


        <el-form ref="form"   label-width="70px" style="width:100%;">
    
             <el-form-item label="名称">
                    <el-input    v-model="mtk_form.cname" placeholder="名称"></el-input>
              </el-form-item> 
 

               <el-row style="width:100%;">
                     <el-col :span="12">
                        <el-form-item label="图片">
                            <el-upload 
                                  action="uploadUrl"  
                                  :show-file-list="false"   
                                  :before-upload="beforeupload"
                                  :http-request="ImgUploadSectionFile">
                                  <div class="avatar-uploader">
                                      <img v-if="pic_form.head_img"  :src="pic_form.head_img" class="avatar">
                                      <i v-else class="el-icon-plus avatar-uploader-icon"></i>
                                  </div>
                            </el-upload>
                         </el-form-item>       
                     </el-col> 

                </el-row> 
                
               <el-form-item label="颜色选择">
                    <el-color-picker v-model="mtk_form.color" size="mini"></el-color-picker> 
               </el-form-item> 
 
                                     
            </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;"  @click="xg_but_qr">确认</el-button>
                
            </div>

        </div> 
    </el-dialog>

    
               <!-- 修改排序 -->
    <el-dialog title="修改排序" :visible.sync="mtk1"  width="400px" :close-on-click-modal="false">
        <div style="width:100%;"> 


        <el-form ref="form"   label-width="70px" style="width:100%;">
    
             <el-form-item label="排序">
                    <el-input    v-model="mtk1_form.num" placeholder="排序"></el-input>
              </el-form-item> 
 
                                     
            </el-form>

            <div style="text-align: center;width:50%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;"  @click="mtk1_but_qr">确认</el-button>
                
            </div>

        </div> 
    </el-dialog>

   </div>
</template>

<script>

export default {
   name: 'shopclassifylist',
   props:{
      datalist:{  
        //type:Array,
       default:()=>[]
     },
  },
  data () {
    return {
        dtheight:'500',  //窗口高度
        xg_mtk:false,
        mtk_form:{
           cname:'',
           color: '#778899'
        },
        pic_form:{
           head_img:'',
           upfile:'',
        }, 
        my_cid:'',
        mtk1:false,
        mtk1_form:{
            num:''
        }
    }
  },
   components:{

  },
  created(){
     this.dtheight = window.innerHeight - 293
      
  },
  mounted (){
    
    
  },
  methods: {
    xg_but(row){
        this.my_cid = row.cid
        this.mtk_form.cname = row.cname
        this.mtk_form.color = row.color
        this.pic_form.upfile = row.icon
        this.pic_form.head_img = this.urlimg + row.icon
        this.xg_mtk = true
    },
    xg_but_qr(){
         this.post("/product/updateCate", {
                cid:this.my_cid,
                cname:this.mtk_form.cname,
                icon:this.pic_form.upfile,
                color:this.mtk_form.color,
              }).then(res => {
                if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.$emit('up_list_fun')
                    this.xg_mtk = false
                }else {
                   this.open1(res.message,'warning')
                }

            })
        
    },
    delect_but(row){
        this.my_cid = row.cid
        this.$confirm('是否删除, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
         }).then(() => {
                this.post("/product/deleteCate", {
                    cid:row.cid,
                }).then(res => {

                    if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.$emit('up_list_fun')
                    }else {
                    this.open1(res.message,'warning')
                }

             })
        }).catch(() => {
                  this.$emit('up_list_fun') 
        });
     },
     mtk1_but(row){
         this.my_cid = row.cid
         this.mtk1_form.num = row.rank
         this.mtk1 = true
     },
     mtk1_but_qr(){
        this.post("/product/sortCate", {
                    cid:this.my_cid,
                    num:this.mtk1_form.num
                }).then(res => {

                    if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.$emit('up_list_fun')
                    this.mtk1 = false
                    }else {
                    this.open1(res.message,'warning')
                }

             })
     },
      beforeupload(file){   //重新写入上穿 需要点击确认上传与表单一起提交
           if(this.upimglx(file) == false){  //判断是否为fales
              this.upimglxtitle()  //执行弹出错误             
              return false
            }  
            var windowURL = window.URL || window.webkitURL;               
            this.pic_form.head_img=windowURL.createObjectURL(file);             
            
            this.upimgpost("/image/uploadMultiple",file).then(res => {
              console.log(res.result.url )
               this.pic_form.upfile = res.result.url    
            })

            return false;
     },
      ImgUploadSectionFile(param){//图片上传    
      },

  }
}
</script>


<style scoped>
.avatar-uploader  {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 150px;
    height: 150px;
    line-height: 150px;
    text-align: center;
  }
  .avatar {
    width: 150px;
    height: 150px;
    display: block;
  }
</style>